import 'package:flutter/material.dart';

class TermsProvider with ChangeNotifier {
  FormFieldState<bool>? _formFieldState;

  FormFieldState<bool>? get formFieldState => _formFieldState;

  // Attach form state (call this once when FormField builds)
  void attachFormField(FormFieldState<bool> formFieldState) {
    _formFieldState = formFieldState;
  }

  // Toggle terms acceptance (directly updates FormFieldState)
  void toggle() {
    if (_formFieldState != null) {
      final newValue = !(_formFieldState!.value ?? false);
      _formFieldState!.didChange(newValue);
      notifyListeners();
    }
  }

  // Clean up to avoid memory leaks
  void detachFormField() {
    _formFieldState = null;
  }
}
